<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
            <el-form-item label="姓名" prop="expertName">
                <el-input v-model="queryParams.expertName" placeholder="请输入姓名" clearable maxlength="10" show-word-limit
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="联系方式" prop="expertContact">
                <el-input v-model="queryParams.expertContact" placeholder="请输入联系方式" clearable maxlength="11"
                    show-word-limit @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item label="排班状态" prop="scheduleStatus">
                <el-select v-model="queryParams.scheduleStatus">
                    <el-option v-for="item in scheduleStatusList" :key="item.id" :value="item.id" :label="item.name">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="首页标识" prop="homeStatus">
                <el-select v-model="queryParams.homeStatus">
                    <el-option v-for="item in homeStatusList" :key="item.id" :value="item.id" :label="item.name">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="warning" icon="el-icon-download" size="mini"  @click="handleExport"
                    v-hasPermi="['business:expert:exportCopy']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <el-table @selection-change="handleSelectionChange" v-loading="loading" :data="expertList">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序号" align="center" width="55" type="index" />
            <el-table-column label="头像" align="center" prop="avatarUrl">
                <template slot-scope="scope">
                    <image-preview :src="scope.row.avatarUrl" :width="50" :height="50" />
                </template>
            </el-table-column>
            <el-table-column label="姓名" align="center" prop="expertName" min-width="100"
                :show-overflow-tooltip="true" />
            <el-table-column label="联系方式" align="center" prop="expertContact" min-width="150"
                :show-overflow-tooltip="true" />
            <el-table-column label="年龄" align="center" prop="age" min-width="100" :show-overflow-tooltip="true" />
            <el-table-column label="性别" align="center" prop="gender" :formatter="formatterCategory" min-width="60" />
            <el-table-column label="职称" align="center" prop="title" :show-overflow-tooltip="true" min-width="150" />
            <el-table-column label="标签" align="center" prop="tags" :show-overflow-tooltip="true" min-width="150" />
            <el-table-column label="咨询领域" align="center" prop="domainName" :show-overflow-tooltip="true"
                min-width="150" />
            <el-table-column label="首页标识" align="center">
                <template slot-scope="scope">
                    <el-switch v-model="scope.row.homeStatus" active-value="1" inactive-value="0"
                        @change="handleStatusChange(scope.row)"></el-switch>
                </template>
            </el-table-column>
            <el-table-column label="排班状态" align="center" prop="scheduleStatus">
                <template slot-scope="scope">
                    <div v-if="scope.row.scheduleStatus == 0">未排</div>
                    <div v-if="scope.row.scheduleStatus == 1">已排</div>
                </template>
            </el-table-column>

            <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" min-width="150" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160" fixed="right">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" @click="viewSetting(scope.row)"
                        v-hasPermi="['business:expert:views']">查看排班</el-button>
                    <el-button size="mini" type="text" @click="handleSetting2(scope.row)"
                        v-hasPermi="['business:expert:setting']">排班</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />
        <viewscheduling ref="viewscheduling" :expertId="expertId" @closeDialog="closeDialog"
            :showSetting="showviewSetting">
        </viewscheduling>
        <schedulingCopy ref="schedulingCopy" :expertId="expertId" @closeDialog="closeDialog"
            :showSetting="showSetting2">
        </schedulingCopy>
    </div>
</template>

<script>
import { listExpert1, updateExpert } from "@/api/expert/expert";
import schedulingCopy from "@/views/expert/expertScheduling/cnps/schedulingCopy.vue";
import viewscheduling from "@/views/expert/expertScheduling/cnps/viewscheduling.vue";
export default {
    name: "ExpertScheduing",
    components: {
        schedulingCopy,
        viewscheduling
    },
    dicts: ['specific', 'sys_user_sex'],
    data() {
        return {
            scheduleStatusList: [
                {
                    id: '0',
                    name: "未排",
                },
                {
                    id: '1',
                    name: "已排",
                },
            ],
            showviewSetting: false,
            homeStatusList: [
                {
                    id: '0',
                    name: "否",
                },
                {
                    id: '1',
                    name: "是",
                }
            ],
            // 专家id
            expertId: '',
            // 排班
            tExpertScheduleList: [],
            // --------------------------------------

            disabled: false,
            showSetting2: false,
            // 流派列表
            expertschoolList: [],
            // 领域列表
            expertDomainList: [],
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 子表选中数据
            checkedTExpertSchedule: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 专家信息表格数据
            expertList: [],
            // 专家排班表格数据
            tExpertScheduleList: [],

            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                expertName: null,
                age: null,
                gender: null,
                city: null,
                avatarUrl: null,
                title: null,
                totalConsultHours: null,
                workingYears: null,
                tags: null,
                introduction: null,
                expertSaying: null,
                isEnabled: null,
                sortOrder: null,
                individualConsultCost: null,
                familyConsultCost: null,
                crowdCode: null,
                crowdName: null,
                domainName: null,
                homeStatus: null,
                expertContact: null,
                scheduleStatus: null
            }
        };
    },
    created() {
        this.getList();
    },
    methods: {
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('/business/expert/export1', {
                ...this.queryParams,
                ids:this.ids
            }, `专家排班_${new Date().getTime()}.xlsx`)
        },
        handleStatusChange(row) {
            this.$modal.confirm('确认要修改首页推荐吗？').then(function () {
                return updateExpert({
                    id: row.id,
                    homeStatus: row.homeStatus
                })
            }).then(() => {
                this.$modal.msgSuccess("修改成功")
            }).catch(function () {
                row.homeStatus = row.homeStatus === "1" ? "0" : "1"
            })
        },
        closeDialog(e) {
            this.showSetting2 = e
            this.showviewSetting = e
        },
        handleSetting2(row) {
            this.expertId = row.id
            // this.$refs.schedulingCopy.getDetail(this.expertId)
            this.showSetting2 = true
        },
        viewSetting(row) {
            this.expertId = row.id
            // this.$refs.viewscheduling.getDetail(this.expertId)
            this.showviewSetting = true
        },
        formatterCategory(row, column) {
            let type = ""
            this.dict.type.sys_user_sex.forEach(item => {
                if (item.value == row.gender) {
                    type = item.label
                }
            })
            return type
        },
        /** 查询专家信息列表 */
        getList() {
            this.loading = true;
            listExpert1(this.queryParams).then(response => {
                this.expertList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        }
    }
};
</script>
<style>
.conflict-row {
    background-color: #fff0f0 !important;
}

.conflict-row:hover>td {
    background-color: #ffe8e8 !important;
}

.schedule-picker,
.time-picker {
    width: 100%;
}
</style>
